/*
 * Copyright (c) 2001, 2002 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
#include "StdAfx.h"

JNIEXPORT void JNICALL Java_net_sourceforge_perforce_api_internal_Error_clear(JNIEnv * env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	error->Clear();
}

JNIEXPORT jboolean JNICALL Java_net_sourceforge_perforce_api_internal_Error_test(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	return error->Test() ? JNI_TRUE : JNI_FALSE;
}

JNIEXPORT jboolean JNICALL Java_net_sourceforge_perforce_api_internal_Error_isInfo(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	return error->IsInfo() ? JNI_TRUE : JNI_FALSE;
}

JNIEXPORT jboolean JNICALL Java_net_sourceforge_perforce_api_internal_Error_isWarning(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	return error->IsWarning() ? JNI_TRUE : JNI_FALSE;
}

JNIEXPORT jboolean JNICALL Java_net_sourceforge_perforce_api_internal_Error_isError(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	return error->IsError() ? JNI_TRUE : JNI_FALSE;
}

JNIEXPORT jboolean JNICALL Java_net_sourceforge_perforce_api_internal_Error_isFatal(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	return error->IsFatal() ? JNI_TRUE : JNI_FALSE;
}

JNIEXPORT jint JNICALL Java_net_sourceforge_perforce_api_internal_Error_getSeverity(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	return error->GetSeverity();
}

JNIEXPORT jstring JNICALL Java_net_sourceforge_perforce_api_internal_Error_formatSeverity(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	
	const char* result = error->FmtSeverity();
	return env->NewStringUTF(result);
}

JNIEXPORT jint JNICALL Java_net_sourceforge_perforce_api_internal_Error_getGeneric(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	return error->GetGeneric();
}

JNIEXPORT jstring JNICALL Java_net_sourceforge_perforce_api_internal_Error_format(JNIEnv* env, jobject jError, jint options)
{
	Error* error = (Error*)getNativeHandle(env, jError);

	StrBuf result;
	error->Fmt(result, options);

	return env->NewStringUTF(result.Text());
}

JNIEXPORT void JNICALL Java_net_sourceforge_perforce_api_internal_Error_construct(JNIEnv* env, jobject jError)
{
	setNativeHandle(env, jError, new Error());
}

JNIEXPORT void JNICALL Java_net_sourceforge_perforce_api_internal_Error_destruct(JNIEnv* env, jobject jError)
{
	Error* error = (Error*)getNativeHandle(env, jError);
	setNativeHandle(env, jError, NULL);

	delete error;
}
